package net.joke.base;

import net.joke.base.components.ActionQueue;
import net.joke.base.components.Expires;
import net.joke.base.components.Position;
import net.joke.base.components.Renderable;
import net.joke.base.components.sub.MoveTarget;
import net.joke.base.render.TextRenderable;

import org.anddev.andengine.entity.scene.Scene;

import com.artemis.Entity;
import com.artemis.World;

/**
 * Classe singleton per generare le entity.
 * Diventa comodo riunire qui la creazione di OGNI tipo di entity che serve nel programma.
 * In questo modo possiamo sempre intervenire con comodo sulle eventuali logiche di creazione.
 * @author Gianluca
 *
 */
public class EntityFactory {
	
	public static final String EFFECTS = "EF";
	public static final String TEXTS = "TX";

	private static EntityFactory instance;
	private EntityFactory() {
		
	}
	protected static synchronized void setInstance(EntityFactory newInstance) {
		instance = newInstance;
	}
	public static synchronized EntityFactory getInstance() {
		if (instance == null) {
			instance = new EntityFactory();
		}
		return instance;
	}
	
	
	public Entity greenPoints(World world, Scene scene, float coordX, float coordY, float points) {
		Entity rv =  world.createEntity();
		rv.setGroup(TEXTS);
		
		// componente posizione
		rv.addComponent(new Position(coordX, coordY));
		// componente Target
		ActionQueue actionQueue = new ActionQueue();
		actionQueue.addAction(new MoveTarget(coordX, coordY - 50, Config.textShiftSpeed ));
		rv.addComponent(actionQueue);
		// Expires, rimane visibile solo per x secondi
		rv.addComponent(new Expires(Config.textLifeMsec));
		// Renderable (lo sprite di AndEngine)
		rv.addComponent(new Renderable(new TextRenderable(Res.greenText(scene, points, coordX, coordY), scene)));
		
		rv.refresh();
		
		return rv;
	}
	
	
	
}
